<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{mix('/css/web/user/shop_brand.css')}}">
    <script src="{{mix('/js/web/image/uploadPreview.min.js')}}"></script>
</head>
<body>
@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
        @include('web.layout.seller_nav')
        <div class="nav_right flr">
            <div class="base_content">
                <?php if(1==1){?>
                    <div class="line_title">品牌添加</div>
                <?php }else{?>
                    <div class="line_title">品牌修改</div>
                <?php } ?>
                <div class="content">
                    <form id="postForm" method="post" enctype="multipart/form-data">
                        <div class="prompt_top">
                            <img src="{{asset('/img/web/user/shop_brand_add_ts.png')}}">所添加的品牌一定要是品牌提供方
                        </div>
                        <div class="prompt_box">
                            <div class="tit fl">品牌名称</div>
                            <div class="input_box fl">
                                <input type="text" class="fl w231" name="name" value="" placeholder="中文名称">
                                <input type="text" class="fr w231" name="alias" value="" placeholder="英文名称">
                                <div class="ts fl">品牌名称由中文名称和英文名称组成</div>
                            </div>
                        </div>
                        <div class="prompt_box">
                            <div class="tit fl">商标注册号\申请号</div>
                            <div class="input_box fl">
                                <input type="text" class="fl w498" name="serial_no" value="" placeholder="商标存在中文名称和项文名称，且非同一注册号，请填写格式：12****23/12****23">
                            </div>
                        </div>
                        <div class="prompt_box">
                            <div class="tit fl">品牌所有人</div>
                            <div class="input_box fl">
                                <input type="text" class="fl w498" name="belongs" value="" placeholder="品牌持有人的名称">
                            </div>
                        </div>
                        <div class="prompt_box">
                            <div class="tit fl">品牌LOGO</div>
                            <div class="input_box fl">
                                <div class="img fl" id="js-photo-show">
                                    <img src="{{asset('/img/web/user/add_imglogo.png')}}" width="88" id="js-photo" />
                                </div>
                                <input type="file" class="fileupload" name="image" style="display:none" id="js-photo-upload" />
                                <input type="hidden" id="img_path" name="img_path" value="" />
                                <div class="ts fl w498">仅支持格式为.PNG .JPG .GIF，大小在5M以内的单张图片上传</div>
                            </div>
                        </div>
                        <div class="prompt_box">
                            <div class="tit fl">品牌简介</div>
                            <div class="input_box fl">
                                <textarea class="fl w498" name="description"></textarea>
                            </div>
                        </div>
                        <input type="button" class="btn_submit" value="确定"  />
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@include('web.layout.footer')
<script>
$(function () {
    // LOGO图上传前预览
    new uploadPreview({UpBtn: "js-photo-upload", DivShow: "js-photo-show", ImgShow: "js-photo"});
    $("#js-photo").click(function () {
        $("#js-photo-upload").trigger("click");

    })
    $("#js-photo-upload").change(function(){
//       console.log(this.files[0])

        var file = this.files[0];//获取file文件对象


        //获取图片 上传阿里云 把返回地址放到页面中
        var formFile = new FormData();
        formFile.append("image", file);
//        alert(11);
        $.ajax({
            url: "/uploads/images",
            type: 'post',
            data: formFile,
            dataType:"json",
            contentType: false,
            processData: false,
            success: function(data) {
                $("#img_path").val(data.path);
            },
            error: function(data) {
                console.log("error");
            }
        });

    });
    $(".btn_submit").click(function () {

        if($('input[name="name"]').val() == '') {
            layer.alert('请输入中文名称', {
                title: '温馨提示'
            });
            return false;
        }
        if($('input[name="alias"]').val() == '') {
            layer.alert('请输入英文名称', {
                title: '温馨提示'
            });
            return false;
        }
        if($('input[name="serial_no"]').val() == '') {
            layer.alert('请输入商标注册号\申请号', {
                title: '温馨提示'
            });
            return false;
        }
        if($('input[name="belongs"]').val() == '') {
            layer.alert('请输入品牌持有人的名称', {
                title: '温馨提示'
            });
            return false;
        }
        if($('input[name="img_path"]').val() == '') {
            layer.alert('请上传品牌LOGO', {
                title: '温馨提示'
            });
            return false;
        }
        if($('textarea[name="description"]').val() == '') {
            layer.alert('请输入品牌简介', {
                title: '温馨提示'
            });
            return false;
        }

        var name=$('input[name="name"]').val();
        var alias=$('input[name="alias"]').val();
        var serial_no=$('input[name="serial_no"]').val();
        var belongs=$('input[name="belongs"]').val();
        var logo=$('input[name="img_path"]').val();
        var description=$('textarea[name="description"]').val();

        if(name.length>64){
            layer.alert('中文名称字数超限', {
                title: '温馨提示'
            });
            return false;

        }
        if(alias.length>64){
            layer.alert('英文名称字数超限', {
                title: '温馨提示'
            });
            return false;

        }
        if(serial_no.length>64){
            layer.alert('商标注册号\申请号字数超限', {
                title: '温馨提示'
            });
            return false;

        }
        $.ajax({
            url:"/member/seller/shop_brand",
            type: "post",
            data: {name:name,alias:alias,serial_no:serial_no,belongs:belongs,logo:logo,description:description},
            dataType:'json',
            success:function(data){
                // alert(data);
                if(0==data.code){
                    layer.alert('品牌申请成功,等待平台处理',{
                        icon: 1
                        },function () {
                            location.href='/member/seller/shop_brand';
                        }
                    );
                }else{
                    layer.alert(data.message,{icon: 0});
                }
            }
        });

    })

})
</script>
</body>
</html>